package org.jeecg.modules.friends.dao.impl;

import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.jeecg.modules.friends.condition.UserPicsCondition;
import org.jeecg.modules.friends.mapper.ext.UserPicsDOExtMapper;
import org.jeecg.modules.friends.model.UserPicsDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserPicsDAOImpl implements org.jeecg.modules.friends.dao.UserPicsDAO {
    @Autowired
    private UserPicsDOExtMapper userPicsDOExtMapper;

    @Override
    public List<UserPicsDO> queryByUserId(Long userId) {
        UserPicsCondition userPicsCondition = new UserPicsCondition();
        UserPicsCondition.Criteria criteria = userPicsCondition.createCriteria();
        criteria.andUserIdEqualTo(userId);
        return userPicsDOExtMapper.selectByCondition(userPicsCondition);
    }

    @Override
    public void deleteByUserId(Long id) {
        UserPicsCondition userPicsCondition = new UserPicsCondition();
        userPicsCondition.createCriteria().andUserIdEqualTo(id);
        userPicsDOExtMapper.deleteByCondition(userPicsCondition);
    }

    @Override
    public Integer insertBatch(List<UserPicsDO> collect) {
        if (CollectionUtils.isEmpty(collect)) {
            throw new IllegalArgumentException("collect is null or empty!");
        }
        int effectRows = collect.stream()
                .map(e -> userPicsDOExtMapper.insertSelective(e))
                .reduce(0, (x, y) -> x + y);
        return effectRows;
    }

    @Override
    public List<UserPicsDO> queryByCondition(UserPicsCondition userPicsCondition) {
        return userPicsDOExtMapper.selectByCondition(userPicsCondition);
    }

    @Override
    public void update(UserPicsDO userPicsDO) {
        userPicsDOExtMapper.updateByPrimaryKeySelective(userPicsDO);
    }
}